package com.papercutting.platform.controller;

import com.papercutting.platform.common.Result;
import com.papercutting.platform.entity.Config;
import com.papercutting.platform.service.ConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统配置控制器
 */
@RestController
@RequestMapping("/api/config")
@RequiredArgsConstructor
public class ConfigController {
    
    private final ConfigService configService;
    
    /**
     * 获取所有配置
     */
    @GetMapping("/list")
    public Result<List<Config>> getAllConfigs() {
        List<Config> configs = configService.findAll();
        return Result.success(configs);
    }
    
    /**
     * 根据配置键获取配置值
     */
    @GetMapping("/value")
    public Result<String> getConfigValue(@RequestParam String key) {
        Config config = configService.findByConfigKey(key);
        if (config != null) {
            return Result.success(config.getConfigValue());
        }
        return Result.error(404, "配置项不存在");
    }
}